package com.lin.pay.wx.sdk;

import com.lin.properties.PayProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Component
public class WxPayConfigImpl extends WXPayConfig {
    private static final Logger log = LoggerFactory.getLogger(WxPayConfigImpl.class);
    @Autowired
    private PayProperties payProperties;

//    @Value("${wdp.wx.appid}")
//    private String appid;
//    @Value("${wdp.wx.mch_id}")
//    private String mchId;
//    @Value("${wdp.wx.apikey}")
//    private String apikey;
//    @Value("${wdp.wx.certurl}")
//    private String certurl;

    @Override
    String getAppID() {
        return payProperties.getWx().get(PayProperties.WX_APPID);
    }

    @Override
    String getMchID() {
        return payProperties.getWx().get(PayProperties.WX_MCHID);
    }

    @Override
    public String getKey() {
        return payProperties.getWx().get(PayProperties.WX_APIKEY);
    }

    @Override
    InputStream getCertStream() {
        try {
            File file = ResourceUtils.getFile(payProperties.getWx().get(PayProperties.WX_CERTURL));
            return new FileInputStream(file);
        } catch (FileNotFoundException e) {
            log.error("read file fail:", e);
        }
//        ClassPathResource classPathResource = new ClassPathResource(certurl);
//        try (InputStream inputStream =classPathResource.getInputStream();){
//            return inputStream;
//        } catch (IOException e) {
//            log.error("read file fail:",e);
//        }
        return null;
    }

    @Override
    IWXPayDomain getWXPayDomain() {
//        IWXPayDomain di=new IWXPayDomain();
        return null;
    }
}
